<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="./node_modules/jquery/dist/jquery.js"></script>
    <title>Document</title>
  </head>
  <body>
    <h1></h1>
    <input type="text" name="username" /><br />
    <input type="text" name="password" /><br />
    <button>按钮</button>
    <script>
      $(function () {
        $("button").click(function () {
          $.ajax({
            type: "post",
            url: "http://localhost:1020/login",
            data: {
              username: $("[name='username']").val(),
              password: $("[name='password']").val()
            },
            dataType: "json"
          }).then(
            res => {
              if (res.code === 1) {
                $("h1").html("登录成功");
              } else {
                $("h1").html("登录失败");
              }
            },
            res => {
              $("h1").html("请求失败");
            }
          );
        });
      });
    </script>
  </body>
</html>
